class Solution(object):
    def rotate(self, matrix):
        n = len(matrix)
        # 转置矩阵
        for i in range(n):
            for j in range(i, n):  # 注意j从i开始避免重复交换
                matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
        # 翻转每一行
        for row in matrix:
            row.reverse()


if __name__ == '__main__':
    matrix = [[1,2,3],[4,5,6],[7,8,9]]
    print(Solution().rotate(matrix))